package com.gxuwz.zlc.controller;

import com.gxuwz.zlc.common.Result;
import com.gxuwz.zlc.entity.Lab;
import com.gxuwz.zlc.entity.RecruitmentPlan;
import com.gxuwz.zlc.service.RecruitmentPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 招聘计划
 */
@Controller
@RequestMapping("recruitmentPlan")
public class RecruitmentPlanController {

    @Autowired
    private RecruitmentPlanService recruitmentPlanService;

    // 查询所有
    @RequestMapping("/findAll")
    @ResponseBody
    public List<RecruitmentPlan> findRecruitmentPlan(){
        List<RecruitmentPlan> recruitmentPlanList = recruitmentPlanService.findRecruitmentPlan();
        return recruitmentPlanList;
    }

    // 查询一个
    @GetMapping("/findOne/{planId}")
    @ResponseBody
    public Result get(@PathVariable String planId){
        RecruitmentPlan recruitmentPlanById = recruitmentPlanService.findRecruitmentPlanById(planId);
        // code=0,msg=成功
        return Result.success(recruitmentPlanById);
    }

    /**
     * 实验技术人员
     * 填写招聘计划
     * @param recruitmentPlan
     * @return
     */
    @RequestMapping("/add")
    @ResponseBody
    public Map addRecruitmentPlan(@RequestBody RecruitmentPlan recruitmentPlan){
        Map<String,String> map = new HashMap<>();
        try {
            // 计划审核status: 0未审核 、 1审核
            recruitmentPlan.setStatus("0");
            recruitmentPlanService.addRecruitmentPlan(recruitmentPlan);
            map.put("code","200");
            map.put("msg","修改成功");
        } catch (Exception e) {
            map.put("code","500");
            map.put("msg","添加失败");
            e.printStackTrace();
        }
        return map;
    }

    // 修改
    @RequestMapping("/update")
    @ResponseBody
    public Map updateRecruitmentPlan(@RequestBody RecruitmentPlan recruitmentPlan){
        System.out.println(recruitmentPlan);
        recruitmentPlanService.updateRecruitmentPlan(recruitmentPlan);
        Map<String,String> map = new HashMap<>();
        map.put("code","200");
        map.put("msg","修改成功");
        return map;
    }

}
